package edu.intec.matsab.persistence;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.Pattern;

/**
 *
 * @author Sabrina
 */
@Entity
@Table(name = "Asignatura")
@NamedQueries({@NamedQuery(name = "Asignatura.findAll", query = "SELECT a FROM Asignatura a"),
@NamedQuery(name = "Asignatura.findByIdAsignatura", query = "SELECT a FROM Asignatura a WHERE a.idAsignatura = :idAsignatura"),
@NamedQuery(name = "Asignatura.findByDescripcion", query = "SELECT a FROM Asignatura a WHERE a.descripcion = :descripcion"),
@NamedQuery(name = "Asignatura.findByCreditos", query = "SELECT a FROM Asignatura a WHERE a.creditos = :creditos"),
@NamedQuery (name = "Asignatura.AllAsignaturas", query = "SELECT a FROM Asignatura a"),
@NamedQuery (name = "Asignatura.AllAsignaturasByEstado", query = "SELECT a FROM Asignatura a WHERE a.idEstado.idEstado =:idEstado")})
public class Asignatura implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotEmpty( message="Este campo es requerido")
    @Pattern(regex = "[a-zA-Z]+", message = "Este campo solo debe contener letras a-z/A-Z")
    @Length(min = 3, max = 3, message="Este campo debe contener 3 caracteres")
    @Id
    @Basic(optional = false)
    @Column(name = "idAsignatura")
    private String idAsignatura;

    @NotEmpty( message="Este campo es requerido")
    @Pattern(regex = "[a-zA-Z ]+", message = "Este campo solo debe contener letras a-z/A-Z")
    @Length(min = 1, max = 50, message="Este campo puede contener un maximo de 50 caracteres")
    @Basic(optional = false)
    @Column(name = "descripcion")
    private String descripcion;

    @NotEmpty( message="Este campo es requerido")
    @Basic(optional = false)
    @Column(name = "creditos")
    private int creditos;

    @JoinColumn(name = "idEstado", referencedColumnName = "idEstado")
    @ManyToOne(optional = false)
    private Estado idEstado;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "asignatura")
    private Collection<Seccion> seccionCollection;
    @Transient
    private boolean selected;

    public Asignatura() {
    }

    public Asignatura(String idAsignatura) {
        this.idAsignatura = idAsignatura;
    }

    public Asignatura(String idAsignatura, String descripcion, int creditos) {
        this.idAsignatura = idAsignatura;
        this.descripcion = descripcion;
        this.creditos = creditos;
    }

    public String getIdAsignatura() {
        return idAsignatura;
    }

    public void setIdAsignatura(String idAsignatura) {
        this.idAsignatura = idAsignatura;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public int getCreditos() {
        return creditos;
    }

    public void setCreditos(int creditos) {
        this.creditos = creditos;
    }

    public Estado getIdEstado() {
        return idEstado;
    }

    public void setIdEstado(Estado idEstado) {
        this.idEstado = idEstado;
    }

    public Collection<Seccion> getSeccionCollection() {
        return seccionCollection;
    }

    public void setSeccionCollection(Collection<Seccion> seccionCollection) {
        this.seccionCollection = seccionCollection;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idAsignatura != null ? idAsignatura.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Asignatura)) {
            return false;
        }

        Asignatura other = (Asignatura) object;
        if ((this.idAsignatura == null && other.idAsignatura != null) || (this.idAsignatura != null && !this.idAsignatura.equals(other.idAsignatura))) {
            return false;
        }

        return true;
    }

    @Override
    public String toString() {
        return "edu.intec.matsab.persistence.Asignatura[idAsignatura=" + idAsignatura + "]";
    }
}